package flexconsole {
	import flexconsole.controller.StartUpCommand;
	import flexconsole.model.ICategoryProxy;
	import flexconsole.model.IConfigProxy;
	import flexconsole.model.ILogMessageProxy;
	import flexconsole.resources.ResourceBundle;
	
	import flexunit.framework.Assert;
	
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.logging.targets.LineFormattedTarget;
	import mx.logging.targets.MiniDebugTarget;
	
	import org.puremvc.as3.patterns.facade.Facade;
	
	public class AppFacade extends Facade {
		
		static public const STARTUP:String = "startup";
		
		static public const SHUTDOWN:String = "shutdown";
		
		static public const CONNECTION:String = "connection";
		
		static public const DATA_CHANGE:String = "dataChange";
		
		static public const PREFERENCE:String = "preference";
		
        static public const CHECK_APP_UPDATE:String = "checkAppUpdate";
        
        static public const HELP:String = "HELP";
		
		static public const PROXYNAME_CONFIG:String = "ConfigProxy";
		
		static public const PROXYNAME_CATEGORY:String = "CategoryProxy";
		
		static public const PROXYNAME_LOG_MESSAGE:String = "LogMessageProxy";
		
		static public const MEDIATORNAME_APP:String = "AppMediator";
		
		static public const MEDIATORNAME_FILTERCONTROLS:String = "FilterControlsMediator";
		
		static public const MEDIATORNAME_GRID:String = "GridMediator";
		
		static public const MEDIATORNAME_TOOLBAR:String = "ToolbarMediator";
		
		static public const MEDIATORNAME_PREFERENCE:String = "PreferenceMediator";
		
		static public const FILENAME_CONFIG:String = "config.xml";
		
		static public const FILENAME_CATEGORY:String = "categories.xml";
		
		static public const FILENAME_LOG:String = "logs.xml";
		
		static private var logger:ILogger = Log.getLogger("flexconsole.ApplicationFacade");
		
		static public function getInstance():AppFacade {
			if (instance == null) {
				instance = new AppFacade();
			}
			return instance as AppFacade;
		}
		
		static public function enableDebug():void {
			var target:LineFormattedTarget = new MiniDebugTarget();
			target.filters = [ "*" ];
			target.includeDate = true;
			target.includeTime = true;
			target.includeCategory = true;
			target.includeLevel = true;
			Log.addTarget(target);
		}
		
		[Bindable]
		public var resourceBundle:ResourceBundle = new ResourceBundle();
		
		public function AppFacade() {
			super();
			logger.debug("ApplicationFacade()");
		}
		
		public function startup(app:FlexConsole):void {
			Assert.assertNotNull(app);
			logger.debug("startup({0})", app);
			sendNotification(STARTUP, app);
		}
		
		public function get configProxy():IConfigProxy {
			return retrieveProxy(PROXYNAME_CONFIG) as IConfigProxy;
		}
		
		public function get categoryProxy():ICategoryProxy {
			return retrieveProxy(PROXYNAME_CATEGORY) as ICategoryProxy;
		}
		
		public function get logMessageProxy():ILogMessageProxy {
			return retrieveProxy(PROXYNAME_LOG_MESSAGE) as ILogMessageProxy;
		}
		
		override protected function initializeController():void {
			super.initializeController();
			registerCommand(STARTUP, StartUpCommand);
		}
	
	}
}